use chrono::NaiveDate;
use polars::df;
use polars::prelude::{DataFrame, ParquetReader, SerReader};
use std::fs::File;
use std::hash::{DefaultHasher, Hasher};

#[test]
fn df_iter() {
    let df: DataFrame = df!(
        "integer" => &[1, 2, 3],
        "date" => &[
                NaiveDate::from_ymd_opt(2025, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(),
                NaiveDate::from_ymd_opt(2025, 1, 2).unwrap().and_hms_opt(0, 0, 0).unwrap(),
                NaiveDate::from_ymd_opt(2025, 1, 3).unwrap().and_hms_opt(0, 0, 0).unwrap(),
        ],
        "float" => &[4.0, 5.0, 6.0],
        "string" => &["a", "b", "c"],
    )
    .unwrap();
    let mut row_index = 0;
    while row_index < 10000 {
        let mut col_index = 0;
        df.schema().iter().for_each(|item| {
            // println!("{} - {}",item.0,item.1);
            let col = df.column(&item.0).unwrap();
            // println!("{}",col.len());
            println!("{:?}", col.get(col_index));
            col_index += 1;
        });
        row_index += 1;
    }
}

#[test]
fn test_string_split() {
    let s = "fdjfhkdhfw,fdsfsdd9,".to_string();
    println!("{}", s[..s.len() - 1].to_string());
}

#[test]
fn test_ahasher() {
    let mut hasher = DefaultHasher::default();
    hasher.write("hello".as_bytes());
    println!("{:?}", hasher.finish());
}

#[test]
fn test_read_parquet() {
    // let file = File::open("/home/zhujianfeng/code/rust/visit-dd/upload/36416498410499").unwrap();
    let file =
        File::open("/home/zhujianfeng/code/rust/visit-dd/db/36249765976068.parquet").unwrap();
    let reader = ParquetReader::new(file);
    let df = reader.finish();
    if df.is_err() {
        println!("{}", df.unwrap_err());
    } else {
        let df = df.unwrap();
        println!("{:?}", df);
    }
}
